﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessStorage
{
    public partial class OuSuisJeService
    {
        /// <summary>
        /// Get All responses associate by enigma (order by PostDate descending)
        /// </summary>
        /// <param name="EnigmaId"></param>
        /// <returns></returns>
        public IQueryable<Response> GetResponsesByEnigma(Guid EnigmaId)
        {
            return Responses.Where(pl => pl.PartitionKey == EnigmaId.ToString()).AsQueryable().OrderByDescending(n => n.PostDate);
        }

        /// <summary>
        /// Get all enigma post by a user (order by PostDate descending)
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public IQueryable<Enigma> GetUserEnigmas(Guid UserId)
        {
            return Enigmas.Where(n => n.UserId == UserId).AsQueryable().OrderByDescending(n => n.PostDate);
        }

        /// <summary>
        /// Returns Enigmas ordered by date, skip and take is available for limit data transfer
        /// </summary>
        /// <param name="skip"></param>
        /// <param name="take"></param>
        /// <returns></returns>
        public IQueryable<Enigma> GetEnigmasOrderedByPostDate(int skip, int take)
        {
            return Enigmas.Take(take).AsQueryable().OrderByDescending(n => n.PostDate).Skip(skip);
        }

        /// <summary>
        /// Find Enigmas around me
        /// ATTENTION : This method is not implemented
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        public IQueryable<Enigma> FindEnigmasAroundMe(long latitude, long longitude)
        {
            return Enumerable.Empty<Enigma>().AsQueryable();
        }

        /// <summary>
        /// Find enigmas of my town
        /// </summary>
        /// <param name="postalcode"></param>
        /// <param name="country"></param>
        /// <returns></returns>
        public IQueryable<Enigma> FindEnigmasAroundMe(string postalcode, string country)
        {
            return Enigmas.Where(pl => pl.PartitionKey == postalcode + " _ " + country).AsQueryable();
        }
    }
}
